package com.abp.service.impl;

import com.abp.entity.UserCluster;
import com.abp.mapper.UserClusterMapper;
import com.abp.service.UserClusterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class UserClusterServiceImpl extends ServiceImpl<UserClusterMapper, UserCluster> implements UserClusterService {
    private final Random random = new Random();

    @Override
    public void generateUserClusters(int userCount, int clusterCount) {
        List<UserCluster> clusterList = new ArrayList<>();

        for (int userId = 1; userId <= userCount; userId++) {
            UserCluster cluster = new UserCluster();
            cluster.setUserId(userId);
            cluster.setClusterId(random.nextInt(clusterCount) + 1);
            clusterList.add(cluster);
        }

        saveBatch(clusterList);
        System.out.println("用户聚类数据生成完毕，共插入：" + clusterList.size() + " 条数据");
    }
}
